const resultEnum = require('../utils/resultEnum').ResultEnum;
const Mock = new(require('../utils/mock')).Mocks();
/* 查询角色信息 */
function selectRoleInfo(ctx, next) {
  try {
    const params = {
      ...ctx.query
    };
    console.log(params);
    /* 模拟查询数据库，处理后返回 */
    /* 返回对象 */
    console.log('resultEnum.GET_ERROR->>>>');
    console.log('resultEnum.GET_ERROR->>>>', resultEnum.GET_ERROR);
    ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getRoleAll())
  } catch (error) {
    ctx.error(resultEnum.GET_ERROR.code, resultEnum.GET_ERROR.msg)
  }
}

/* 查询角色信息 */
function selectRoleAllInfo(ctx, next) {
  try {
    const params = {
      ...ctx.query
    };
    console.log(params);
    /* 返回对象 */
    if (ctx.request.header.authorization === 'Bearer 11') {
      ctx.error(resultEnum.GET_ACCESS_TOKEN_Expired.code, resultEnum.GET_ACCESS_TOKEN_Expired.msg)
    } else {
      ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getRoleAll())
    }
  } catch (error) {
    ctx.error(resultEnum.GET_ERROR.code, resultEnum.GET_ERROR.msg)
  }
}

/* 查询角色信息通过id */
function selectRoleInfoById(ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getRoleById())
}

/* 新增角色信息 */
function insertRole(ctx, next) {
  const params = {
    ...ctx.request.body
  };
  console.log(params);
  ctx.success(resultEnum.SAVE_SUCCESS.code, resultEnum.SAVE_SUCCESS.msg)
}

/* 更新角色信息 */
function updateRole(ctx, next) {
  const params = {
    ...ctx.request.body,
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.UPDATE_SUCCESS.code, resultEnum.UPDATE_SUCCESS.msg)
}

/* 删除角色信息 */
function deleteRole(ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.DELETE_SUCCESS.code, resultEnum.DELETE_SUCCESS.msg)
}

module.exports = {
  selectRoleInfo,
  selectRoleAllInfo,
  selectRoleInfoById,
  insertRole,
  updateRole,
  deleteRole
}